package com.tianqu.tms.www.cardect.controller;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.security.TmsUserProfile;
import com.tianqu.tms.entity.TmsDetectInfo;
/**
 * 
 * 待确认转检测完了（如导出CSV）controller
 * 
 * @author tianshifu
 *
 */
public class CarWaitConfirmToDectoverResultController extends TmsController {
	private Logger logger = Logger.getLogger(CarWaitConfirmToDectoverResultController.class);//log
	private static final String ALLOCATEID = "carSerial";//定义页面checkbox的property
	private static final String ADDMODE    = "addModel";//转录入模式 1 人工 2 ipad
	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();

		//添加事务提交异常捕获
		try {
			controller.begin();

			//从uc中获取检测模式和车辆ID集合
			String addMode = (String)uc.getAttribute(ADDMODE);//获取录入模式
			
			String[] carSerial = (String[]) uc.getAttribute(ALLOCATEID);//获取选中ID
			
			TmsUserProfile profile = uc.getUserProfile();
			
			//根据录入模式和车辆ID批量更新数据
			TmsDetectInfo car = TmsDetectInfo.getInstance();
			
			//car.deleteDectInfoBySerialCollection(carSerial);
			
			car.updateCarInfoBySerialCollectionAndAddMode(carSerial,addMode,profile.getUniqueId());

			
			//从uc中将录入模式和选中车辆ID组移除掉
			uc.removeAttribute(ADDMODE);
			uc.removeAttribute(ALLOCATEID);
			
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR,e1);
			}
			//系统异常
			if(e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR,e);
		}

		logger.debug(this.getClass().getName() + "#doAction was completed.");
	}
}

